import { defineStore } from 'pinia';


interface ObjectList {
    [key: string]: string[];
}

export const usePermissStore = defineStore('permiss', {
    state: () => {
        const username = localStorage.getItem('vuems_name');
        const storedPermissions = localStorage.getItem('vuems_permiss');
        const defaultList: ObjectList = {
            admin: [
                '0',
                '1',
                '2',
                '3',
                '4',
                '5',
                '6',
                '7',
                '8',
                '9',
                '10',
                '11',
                '12',
                '13',
            ],
            ...(username && storedPermissions ? { [username]: storedPermissions.split(',') } : {}),
        };
        return {
            key: (username == 'admin' ? defaultList.admin : defaultList[username]) as string[],
            defaultList,
        };
    },
    actions: {
        handleSet(val: string[]) {
            this.key = val;
        },
    },
});
